package br.ufmg.dcc.simulesspl.model;

import java.util.List;

import br.ufmg.dcc.simulesspl.exception.InvalidSelectionException;
import br.ufmg.dcc.simulesspl.model.EngineerCard;

public class EngineerSelection {

	private List<EngineerCard> engineers;
	private EngineerCard selectedDeveloper;
	private EngineerCard selectedBugFixer;

	public EngineerSelection() {
		engineers = EngineerCard.create(3);
	}

	public List<EngineerCard> getEngineerOptions() {
		return engineers;
	}

	public void select(String selection) throws InvalidSelectionException {
		try {

			selectedDeveloper = null;
			selectedBugFixer = null;

			String[] s = selection.trim().split(" ");
			Integer id = Integer.valueOf(s[0]);
			String command = s.length > 1 ? s[1].toLowerCase() : null;

			if (command == null || command.toLowerCase().equals("develop")) {
				this.selectedDeveloper = engineers.get(id - 1);
			} else if (command.equals("bugfix")) {
				this.selectedBugFixer = engineers.get(id - 1);
			} else {
				throw new InvalidSelectionException();
			}
		} catch (Exception e) {
			throw new InvalidSelectionException();
		}
	}

	public EngineerCard getSelectedDeveloper() {
		return selectedDeveloper;
	}

	public EngineerCard getSelectedBugFixer() {
		return selectedBugFixer;
	}

}
